from common.base import Base, By
from selenium.webdriver.support.ui import Select


class BackStageIndex(Base):
    """这是后台index主页面的page"""

    def change_menu_frame(self):
        """切换菜单栏frame"""
        # 定位菜单栏frame
        frame = self.find_element((By.ID, 'menu-frame'))
        # 切换到菜单栏frame
        self.driver.switch_to.frame(frame)

    def order_manage(self):
        """点击订单管理"""
        self.click((By.XPATH, '//*[@id="menu-ul"]/li[4]'))

    def send_order_number(self, order_number):
        """定位订单号搜索框,输入订单号"""
        self.send_key((By.ID, 'order_sn'), order_number)

    def order_status_select(self, index):
        """定位订单管理中的订单状态下拉框选择下拉内容, 传入下拉内容的下标"""
        # 定位下拉框位置
        s1 = self.find_element((By.ID, 'status'))
        # 创建select类的实例对象
        select = Select(s1)
        select.select_by_index(index)

    def btn_search(self):
        """定位订单管理中的搜索按钮,并点击"""
        self.click((By.XPATH, '/html/body/div[3]/form/input[3]'))

    def order_no1(self):
        """获取最新的一条订单编号的号码"""
        return self.get_element_text((By.XPATH, '//*[@id="order_0"]'))

    def click_order_no1(self):
        """点击第一个订单编号"""
        self.click((By.XPATH, '//*[@id="order_0"]'))

    def order_number(self):
        """获取订单信息页里的订单号"""
        return self.get_element_text((By.XPATH, '/html/body/form/div[1]/table/tbody/tr[3]/td[2]'))

    def change_default_frame(self):
        """切换到默认frame"""
        self.driver.switch_to.default_content()

    def change_parent_frame(self):
        """切换到上一级frame"""
        self.driver.switch_to.parent_frame()

    def change_main_frame(self):
        """切换到主框架frame"""
        frame = self.find_element((By.ID, 'main-frame'))
        self.driver.switch_to.frame(frame)
